package redis

import (
	"fmt"
	"github.com/redis/go-redis/v9"
	"wms/settings"
)

var (
	RDB *redis.Client
	Nil = redis.Nil
)

// Init 初始化连接
func Init(cfg *settings.RedisConfig) (err error) {
	client := redis.NewClient(&redis.Options{
		Addr:         fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
		Password:     cfg.Password,
		DB:           cfg.DB,
		PoolSize:     cfg.PoolSize,
		MinIdleConns: cfg.MinIdleConns,
	})
	RDB = client
	return nil
}

func Close() {
	_ = RDB.Close()
}
